forum

home / developersection / forums / how to recognize uitapgesturerecognizer to specific views in controller?

How to recognize UITapGestureRecognizer to specific views in controller?

Anonymous User 2326 17-Oct-2014
I have a menu controller that when it pops up has a collection view. The way it works is that when the user taps outside the collection view it should make the menu dismiss. The menu dismisses when you tap outside the collection view, but it also dismisses when you tap inside the collection view. I can't seem to get the gesture recognizer to only dismiss when it is not inside the collection view. I have looked around on here and google and I haven't found any solution yet that works. Here is the code for the function that handles the tap:

    @IBAction func handleTap(sender: MenuTapGestureRecognizer)
    {
        if (sender.state == .Ended && sender.view == menuCollectionView)
        {
            NSLog("menuCollectionView")
        }
        else if (sender.state == .Ended && sender.view == mainView)
        {
            self.dismissViewControllerAnimated(true, completion: nil)
        }
    }

Updated on 17-Oct-2014

I am a content writter !

Can you answer this question?

Answer

1 Answers

Liked By